package com.pengliu.config;

import javax.servlet.MultipartConfigElement;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.StandardPasswordEncoder;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.pengliu.dll.Ocr_dll;
import com.pengliu.util.Constants;

@Configuration
public class CommonConfig extends WebMvcConfigurerAdapter{
	
	@Bean
    public PasswordEncoder passwordEncoder() {
        return new StandardPasswordEncoder(Constants.PWDKEY);
    }
	
	/**
     * 手工修改密码时使用此方法
     */
    public static void main(String[] args) {
        System.out.println(new StandardPasswordEncoder(Constants.PWDKEY).encode("123456"));
    }
	
	/**
	 * user: pengliu
	 * date: 2017年9月25日
	 * desc: 映射地址
	 * @param registry
	 */
	public void addViewControllers(ViewControllerRegistry registry) {
		//登陆页
		registry.addViewController("/login").setViewName("login");
		//首页映射
		registry.addViewController("/").setViewName("index");
		registry.addViewController("/index").setViewName("index");
	}
	
	@Bean
	public int initOCR() {
		//初始化验证码识别静态库
		return Ocr_dll.INSTANCE.init();
	}
	
	@Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        // 设置文件大小限制
        factory.setMaxFileSize("1024MB"); // KB,MB
        /// 设置总上传数据总大小
        factory.setMaxRequestSize("1024MB");
        return factory.createMultipartConfig();
    }
}

